package com.group.project.hrms.service.impl;

import com.group.project.hrms.entity.AttendanceGroupStaffAdjustRecord;
import com.group.project.hrms.mapper.AttendanceGroupStaffAdjustRecordMapper;
import com.group.project.hrms.service.IAttendanceGroupStaffAdjustRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class AttendanceGroupStaffAdjustRecordService implements IAttendanceGroupStaffAdjustRecordService {

    @Autowired
    private AttendanceGroupStaffAdjustRecordMapper attendanceGroupStaffAdjustRecordMapper;

    @Override
    public int insertAttendanceGroupStaffAdjustRecord(AttendanceGroupStaffAdjustRecord attendanceGroupStaffAdjustRecord) {
        return attendanceGroupStaffAdjustRecordMapper.insert(attendanceGroupStaffAdjustRecord);
    }

    @Override
    public int deleteAttendanceGroupStaffAdjustRecord(AttendanceGroupStaffAdjustRecord attendanceGroupStaffAdjustRecord) {
        return attendanceGroupStaffAdjustRecordMapper.delete(attendanceGroupStaffAdjustRecord);
    }

    @Override
    public int updateAttendanceGroupStaffAdjustRecord(AttendanceGroupStaffAdjustRecord attendanceGroupStaffAdjustRecord) {
        return 0;
    }

    @Override
    public List<AttendanceGroupStaffAdjustRecord> selectAttendanceGroupStaffAdjustRecordByGroupID(String groupID) {
        Example example = new Example(AttendanceGroupStaffAdjustRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orEqualTo("attendanceGroupId" , groupID);
        return attendanceGroupStaffAdjustRecordMapper.selectByExample(example);
    }

    @Override
    public List<AttendanceGroupStaffAdjustRecord> selectAttendanceGroupStaffAdjustRecordByPreGroupID(String pGroupID) {
        Example example = new Example(AttendanceGroupStaffAdjustRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orEqualTo("previousGroupId" , pGroupID);
        return attendanceGroupStaffAdjustRecordMapper.selectByExample(example);
    }

    @Override
    public List<AttendanceGroupStaffAdjustRecord> selectAttendanceGroupStaffAdjustRecordByContactID(String contactID) {
        Example example = new Example(AttendanceGroupStaffAdjustRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orEqualTo("contactId" , contactID);
        return attendanceGroupStaffAdjustRecordMapper.selectByExample(example);
    }

    @Override
    public List<AttendanceGroupStaffAdjustRecord> selectGroupStaffAdjustRecordByContactIDAndYear(String contactID, String year, int flag) {
        Example example = new Example(AttendanceGroupStaffAdjustRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("contactId" , contactID);
        criteria.andEqualTo("action" , flag);
        criteria.andLike("dateInForce", "%" + year + "%");
        return attendanceGroupStaffAdjustRecordMapper.selectByExample(example);
    }

    @Override
    public List<AttendanceGroupStaffAdjustRecord> selectAttendanceGroupStaffAdjustRecordByMonth(String month) { //月份的数据结构为：2022-04
        Example example = new Example(AttendanceGroupStaffAdjustRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("dateInForce", "%" + month + "%");
        return attendanceGroupStaffAdjustRecordMapper.selectByExample(example);
    }

    @Override
    public List<AttendanceGroupStaffAdjustRecord> selectAttendanceGroupStaffAdjustRecordByTwoMonth(String monthA, String monthB) {
        Example example = new Example(AttendanceGroupStaffAdjustRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("dateInForce", "%" + monthA + "%");
        criteria.orLike("dateInForce", "%" + monthB + "%");
        return attendanceGroupStaffAdjustRecordMapper.selectByExample(example);
    }

    @Override
    public List<AttendanceGroupStaffAdjustRecord> selectAllAttendanceGroupStaffAdjustRecord() {
        return null;
    }
}
